<form id="frm_category_edit" method="POST" action="<?php echo $save_action; ?>">
    <?php $this->load->view('cms/category/message'); ?>
    <input id="entity_id" type="hidden" name="id" value="<?php echo $category->id; ?>" />
    <div class="clearfix auto_height mb_10">
        <?php $this->load->view('admin/cms/category/buttons'); ?>
    </div>
    <div class="form_block">
        <div class="block_header">
            Thông tin căn bản
        </div>
        <div class="block_content">
            <table cellpadding="0px" cellspacing="0px">
                <tr>
                    <td class="frm_label">Tên chuyên mục(*)</td>
                    <td class="frm_field">
                        <input type="text" class="std_input required" name="data[name]" value="<?php echo get_field($category, 'name'); ?>" />
                    </td>
                </tr>
                <tr>
                    <td class="frm_label">Bí danh(*)</td>
                    <td class="frm_field">
                        <input type="text" class="std_input" name="data[alias]" value="<?php echo get_field($category, 'alias'); ?>" />
                    </td>
                </tr>	
                <tr>
                    <td class="frm_label">Chọn chuyên mục cha(*)</td>
                    <td class="frm_field">
                        <select style="width: 300px" name="data[parent_id]">
                            <option value="0">--Là chuyên mục gốc--</option>
                            <?php foreach ($parents as $parent) :?>
                            <option value="<?php echo $parent->id; ?>" <?php if ($parent->id == get_field($category, 'parent_id')) :?>selected="selected"<?php endif; ?>)><?php echo get_field($parent, 'name'); ?></option>
                            <?php endforeach; ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="frm_label">Thứ tự(*)</td>
                    <td class="frm_field">
                        <input type="text" class="std_input required" name="data[sort_order]" value="<?php echo get_field($category, 'sort_order'); ?>" />
                    </td>
                </tr>
                <tr>
                    <td class="frm_label">Số bài viết trên mỗi trang(*)</td>
                    <td class="frm_field">
                        <input type="text" class="std_input required" name="data[article_per_page]" value="<?php echo get_field($category, 'article_per_page'); ?>" />
                    </td>
                </tr>
                <tr>
                    <td class="frm_label">Loại danh mục</td>
                    <td class="frm_field">
                        <select style="width: 300px" id="cat_type" name="data[type]">
                            <option value="1">Danh mục hệ thống</option>
                            <option value="2">Danh mục liên quan</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="frm_label">Kích hoạt(*)</td>
                    <td class="frm_field">
                        <select style="width: 300px" id="category_is_active" name="data[is_active]">
                            <option value="0">--Trạng thái kích hoạt--</option>
                            <option value="1">Có</option>
                            <option value="2">Không</option>
                        </select>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div class="form_block">
        <div class="block_header">
            Thông tin SEO
        </div>
        <div class="block_content">
            <table cellpadding="0px" cellspacing="0px">
                <tr>
                    <td class="frm_label">Tiêu đề(*)</td>
                    <td class="frm_field">
                        <input type="text" class="std_input" name="data[meta_title]" value="<?php echo $category->meta_title ?>" />
                    </td>
                </tr>
                <tr>
                    <td class="frm_label">Từ khóa(*)</td>
                    <td class="frm_field">
                        <input type="text" class="std_input" name="data[meta_keywords]" value="<?php echo $category->meta_keywords ?>" />
                    </td>
                </tr>	
                <tr>
                    <td class="frm_label">Mô tả(*)</td>
                    <td class="frm_field">
                        <textarea class="std_editor"  name="data[meta_description]"><?php echo $category->meta_description ?></textarea>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div class="form_block" id="category_article_container">
        <div class="block_header">
            Bài viết trong chuyên mục
        </div>
        <div class="block_content">
            <?php if (isset($collection) && count($collection) != 0) : ?>
                <div class="block">
                    <table class="gridview" width="100%" cellpadding="0" cellspacing="0" border="0">
                        <thead>
                        <tr>
                            <td width="30px"><b>ID</b></td>
                            <td><b>Tiêu đề</b></td>
                        </tr>
                        </thead>
                        <tbody>
                        <?php foreach ($collection as $article) : ?>
                        <tr>
                            <td valign="top">
                                <?php echo $article->id; ?>
                            </td>
                            <td valign="top">
                                <div class="bl">
                                    <div class="frame" style="width: 100px; height: 80px; overflow: hidden;">
                                        <img width="100px" src="<?php echo render_src($article->image); ?>" />
                                    </div>
                                </div>
                                <div class="bl ml_10" style="min-width: 500px">
                                    <p><strong><a href="<?php echo site_url('admin/cms/article/edit/id/' . $article->id . '/return', true); ?>"><?php echo get_field($article, 'title'); ?></a></strong></p>
                                    <p class="small_datetime"><span class="icon icon_author"></span> Gửi bởi: <strong><?php echo get_field($article, 'author'); ?></strong> - Ngày gửi: <strong><?php echo render_date(get_field($article, 'created_at')); ?></strong> - Xuất bản: <strong><?php echo render_date(get_field($article, 'publish_day')); ?></strong></p>
                                    <p class="small_datetime" style="width: 600px">
                                        <?php echo $article->description; ?>
                                    </p>
                                    <p class="mt_10">
                                        <strong><a title="Chỉnh sửa" class="icon icon_edit" href="<?php echo site_url('admin/cms/article/edit/id/' . $article->id . '/return/deleted', true); ?>"></a></strong>
                                        <strong><a title="Xóa bài viết" class="icon icon_delete" href="<?php echo site_url('admin/cms/article/delete/id/' . $article->id . '/return/deleted', true); ?>"></a></strong>
                                        <strong><a title="Xem trước bài viết" onclick="return admin_cms_article.preview_article(<?php echo $article->id; ?>)" class="icon icon_preview" href="<?php echo site_url('admin/cms/article/preview_article/id/' . $article->id . '/return/deleted', true); ?>"></a></strong>
                                    </p>
                                    <div class="bl">
                                        <div class="bl">
                                            <input id="chk_<?php echo $article->id; ?>_hot_article" onclick="return admin_cms_article.update_hot_article(this)" type="checkbox" value="<?php echo $article->id; ?>" <?php if (get_field($article, 'hot_article') == 1) :?>checked="checked"<?php endif; ?>/>
                                        </div>
                                        <div class="bl">
                                            <label for="chk_<?php echo $article->id; ?>_hot_article" style="line-height: 20px; margin-left: 2px">Tiêu điểm</label>
                                        </div>
                                    </div>
                                    <div class="bl ml_10">
                                        <div class="bl">
                                            <input id="chk_<?php echo $article->id; ?>_top_home" onclick="return admin_cms_article.update_top_home(this)" type="checkbox" value="<?php echo $article->id; ?>" <?php if (get_field($article, 'top_home') == 1) :?>checked="checked"<?php endif; ?>/>
                                        </div>
                                        <div class="bl">
                                            <label for="chk_<?php echo $article->id; ?>_top_home" style="line-height: 20px; margin-left: 2px">Nổi bật trang chủ</label>
                                        </div>
                                    </div>
                                    <div class="bl ml_10">
                                        <div class="bl">
                                            <input id="chk_<?php echo $article->id; ?>_top_category" onclick="return admin_cms_article.update_top_category(this)" type="checkbox" value="<?php echo $article->id; ?>" <?php if (get_field($article, 'top_category') == 1) :?>checked="checked"<?php endif; ?>/>
                                        </div>
                                        <div class="bl">
                                            <label for="chk_<?php echo $article->id; ?>_top_category" style="line-height: 20px; margin-left: 2px">Nổi bật mục</label>
                                        </div>
                                    </div>
                                </div>
                            </td>
                        </tr>
                            <?php endforeach; ?>
                        </tbody>
                        <tfoot>

                        </tfoot>
                    </table>
                </div>
            <?php else :?>
            <div style="padding: 10px;">
                <p>Chưa có bài viết nào trong chuyên mục này</p>
            </div>
            <?php endif; ?>
        </div>
    </div>
</form>
<script type="text/javascript">
    $("#category_is_active").val("<?php echo get_field($category, 'is_active'); ?>");
    $("#cat_type").val("<?php echo get_field($category, 'type'); ?>");
    $(".active_item").click(function() {
        var item = $(this).attr("item"); 
        $(item).trigger("click");
        return false;
    });
</script>